#include "icon.h"
#include <iostream>

static struct {
  DWORD id;
  int size;
} iconIds_[] = {
  { 100, 16 },
  { 100, 32 },
  { 101, 16 },
  { 101, 32 },
  { 102, 16 },
  { 102, 32 },
  { 103, 16 },
  { 103, 32 },
  { 104, 16 },
  { 104, 32 },
  { 106, 16 },
  { 106, 32 },
};

HICON loadIcon(DWORD ico, int size) {
  HMODULE hMod = GetModuleHandle(_T("user32.dll"));
  return (HICON)::LoadImage(hMod, MAKEINTRESOURCE(ico), IMAGE_ICON, size, size, LR_SHARED);
}

HICON loadBmp(LPCTSTR file) {
  auto hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  if (!hbitmap) return NULL;
  auto hicon = IconFile::hbitmap2hicon(hbitmap);
  ::DeleteObject(hbitmap);
  return hicon;
}

int _tmain(int argc, TCHAR* argv[]) {
  if (argc < 2) {
    std::cout << "Give a bmp file please." << std::endl;
    return 0;
  }

  IconFile ico;
  for (int i = 0; i < ARRAYSIZE(iconIds_); ++i) {
    auto d = iconIds_[i];
    ico.add(loadIcon(d.id, d.size));
  }
  ico.Save(_T("test.ico"));

  ico.clear();
  ico.add(loadBmp(argv[1]));
  ico.Save(_T("bmp2icon.ico"));
  return 0;
}